package com.qiqu.controller;


import com.qiqu.Vo.UsersVo;
import com.qiqu.commen.Const;
import com.qiqu.utils.JSONResult;
import com.qiqu.utils.RedisOperator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;


/**
 * @author Administrator
 */
@RestController
@Api(value = "基础接口",tags = {"基础接口"})
@RequestMapping("basic")
public class BasicController {

    @Resource
    RedisOperator redisOperator;

    @ApiOperation(value = "获取一个验证码--fk",notes = "获取一个验证码")
    @ApiImplicitParam(name = "wx", value = "微信号", required = true, dataType = "string", paramType = "query")
    @GetMapping("/getCode")
    public JSONResult getCode(String wx) {
        UsersVo user =new UsersVo();
        String str = Const.USER_REDIS_SESSION+":"+wx;
        String getToken = redisOperator.get(str);
        if(getToken==null){
            String token= UUID.randomUUID().toString();
            redisOperator.set( str,token,Const.TOKEN_AGE);
            getToken=token;
        }
        user.setWeixin(wx);
        user.setToken(getToken);
        return new JSONResult(JSONResult.ok(user));
    }
}
